﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Adaptive_Clustering
{
    public class BiLinearInterpulation
    {
        public BiLinearInterpulation()
        {

        }

        public Byte biLinearInterpulation(Byte[,] ImageArray, int x, int y)
        {
            Byte Q11, Q12, Q21, Q22;
            float R1, R2, P;
            int x1, x2, y1, y2;
            x1 = x - 1;
            x2 = x + 1;
            y1 = y + 1;
            y2 = y - 1;
            Q11 = ImageArray[x1, y1];
            Q12 = ImageArray[x1, y2];
            Q21 = ImageArray[x2, y1];
            Q22 = ImageArray[x2, y2];

            R1 = ((float)(x2 - x) / (float)(x2 - x1)) * (float)Q11 + ((float)(x - x1) / (float)(x2 - x1)) * (float)Q21;
            R2 = ((float)(x2 - x) / (float)(x2 - x1)) * (float)Q12 + ((float)(x - x1) / (float)(x2 - x1)) * (float)Q22;
            P = ((float)(y2 - y) / (float)(y2 - y1)) * (float)R1 + ((float)(y - y1) / (float)(y2 - y1)) * (float)R2;

            return (Byte)P;
        }
    }
}
